package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;

/**
 * 分析：
 * 
 * 实现：
 * 
 * 经验：
 * 第二次提交就过了。只修改了两个地方：
 * 1) 所有的数组用int[]，不用Integer[]
 * 2) 输出结果，一开始偷懒，用Arrays.asList(w).toString().replaceAll("\\[|\\]", "").replaceAll(",", " ")
 * 后来改用循环搞定。
 * 
 * 教训：应该有更好的做法，不需要恢复原来的状态s就直接计算得到w。
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1068 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1068.class.getResource("P1068.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		int t = Integer.valueOf(line);
		
        for (int i = 0; i < t; i ++) {
        	line = stdin.readLine();

        	line = stdin.readLine();
        	String[] tmp = line.split(" ");
        	int[] p = new int[tmp.length];
	        for (int j = 0; j < tmp.length; j ++) {
	        	p[j] = Integer.valueOf(tmp[j]);
	        }
	        int[] w = parencodings(p);
	        for (int j = 0; j < w.length; j ++) {
	        	if (j != 0) {
	        		System.out.print(" ");
	        	}
		        System.out.print(w[j]);
	        }
	        System.out.println();
        }
	}

	private static int[] parencodings(int[] p) {
		return s2w(p2s(p));
	}

	private static char[] p2s(int[] p) {
		
		char[] s = new char[2*p.length];
		int c = 0;
		for (int i = 0; i < p.length; i ++) {
			int t = (i == 0)?p[i]:p[i]-p[i-1];
			for (int j = 0; j < t; j ++) {
				s[c+j] = '(';
			}
			s[c + t] = ')';
			c += t+1;
		}
		return s;
	}
	
	private static int[] s2w(char[] s) {

		int[] x = new int[s.length/2];
		int[] y = new int[s.length/2];
		int n = 0;
		for (int i = 0; i < s.length; i ++) {
			if (s[i] == ')') {
				y[n] = i;
				//get x[n] here
				int d = 1;
				int k = i;
				while (d != 0) {
					k --;
					if (s[k] == ')') d ++;
					else d --;
				}
				x[n] = k;
				
				n ++;
			}
		}
		
		int[] w = new int[s.length/2];
		for (int i = 0; i < w.length; i ++) {
			w[i] = 0;
			for (int j = x[i]; j <= y[i]; j ++) {
				if (s[j] == ')') w[i]++;
			}
		}
		return w;
	}
}
